//
//  HWSetZhongXingViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/28.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWSetZhongXingViewController.h"
#import "HWsetUpCell.h"
#import "HWWebViewGameViewController.h"

#import <SDWebImage/SDImageCache.h>
#import "SDImageCache.h"





@interface HWSetZhongXingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSMutableArray *dataMutable;





@end

@implementation HWSetZhongXingViewController


-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
       // _mainaTableVie.backgroundColor = RGB(241, 242, 244);
        
    }
    return   _mainaTableVie ;

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加数据
    [self addData];
    // Do any additional setup after loading the view.
    // 设置UI
    [self setupUI];
}

-(void)addData {
//    @property(strong,nonatomic) NSString *titltStr;
//    @property(strong,nonatomic) NSString *rightStr;
//    @property(assign,nonatomic) BOOL kaiguan; // 开关
//    @property(strong,nonatomic) NSString *shifouxianshiKaiguan; // 1.代表显示开关 2. 代表不显示开关
    
    self.dataMutable = [[NSMutableArray alloc]init];
    HWSetupModel *mdel1 = [[HWSetupModel alloc]init];
    mdel1.titltStr = @"消息推送";
    mdel1.rightStr = @"V2.0";
    mdel1.kaiguan = NO;
    mdel1.shifouxianshiKaiguan = @"1";
    [self.dataMutable addObject:mdel1];
    
     HWSetupModel *mdel2 = [[HWSetupModel alloc]init];
     mdel2.titltStr = @"检查更新";
     mdel2.rightStr = @"V2.0";
     mdel2.kaiguan = NO;
     mdel2.shifouxianshiKaiguan = @"2";
     [self.dataMutable addObject:mdel2];
    
     HWSetupModel *mdel3 = [[HWSetupModel alloc]init];
     mdel3.titltStr = @"清除缓存";
     mdel3.rightStr = @"10.6M";
     mdel3.kaiguan = NO;
     mdel3.shifouxianshiKaiguan = @"2";
    
    
     NSUInteger intg = [[SDImageCache sharedImageCache] totalDiskSize];
    

     NSString * currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeWithInterge:intg]];


     mdel3.rightStr = currentVolum;
    
    
    
     [self.dataMutable addObject:mdel3];
    
     HWSetupModel *mdel4 = [[HWSetupModel alloc]init];
     mdel4.titltStr = @"用户隐私协议";
   
     mdel4.rightStr = @"";
     mdel4.kaiguan = NO;
     mdel4.shifouxianshiKaiguan = @"2";
     [self.dataMutable addObject:mdel4];
    
    
    
    
}

- (NSString *)fileSizeWithInterge:(NSInteger)size{
    // 1k = 1024, 1m = 1024k
    if (size < 1024) {// 小于1k
        return [NSString stringWithFormat:@"%ldB",(long)size];
    }else if (size < 1024 * 1024){// 小于1m
        CGFloat aFloat = size/1024;
        return [NSString stringWithFormat:@"%.0fK",aFloat];
    }else if (size < 1024 * 1024 * 1024){// 小于1G
        CGFloat aFloat = size/(1024 * 1024);
        return [NSString stringWithFormat:@"%.1fM",aFloat];
    }else{
        CGFloat aFloat = size/(1024*1024*1024);
        return [NSString stringWithFormat:@"%.1fG",aFloat];
    }
}





// 设置中心
- (void)setupUI {
    
    self.navigationItem.title = @"设置中心";
    self.navigationItem.title  = [HWjianzhiduiObject keylocalization:@"设置中心"];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainaTableVie];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataMutable.count;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    
    HWsetUpCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[HWsetUpCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    HWSetupModel *model = self.dataMutable[indexPath.row];
    cell.model = model;
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  40;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    
    if (indexPath.row == 0) {
        
    } else if (indexPath.row == 1){
        
         [MBProgressHUD showError:@"此版本为最新版本"];
        
        
        
    }else if (indexPath.row == 2){
        
        
             
             [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
                 
                 HWSetupModel *mdel3 =      self.dataMutable[2];
                 mdel3.rightStr = @"0B";
                 
                 [self.mainaTableVie reloadData];
                 
             }];
             
             [MBProgressHUD showError:@"清除缓存成功"];
                
        
        
        
    }else if (indexPath.row == 3){
        
        

        HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
        webview.urlString = [NSString stringWithFormat:@"%@?ct=zhanwu&ac=agreement&id=2&language=%@",[HWOCGlobalConst baseUrl],[HWjianzhiduiObject returnLanguageAcquisition]];
        webview.gname =@"用户隐私协议";
        webview.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:webview animated:YES];

        
    }
}

@end
